﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Configuration;
using System.IO;

namespace Cliente
{
    class Config
    {
        private string ip_manager = "";
        private int puerto_manager;
        private string path = "";

        public Config(string path)
        {
            this.path = path;
            CargarConfiguracion();
        }

        public string Ip_manager
        {
            get { return ip_manager; }
            set { ip_manager = value; }
        }

        public int Puerto_manager
        {
            get { return puerto_manager; }
            set { puerto_manager = value; }
        }


        private void CargarConfiguracion()
        {

            Console.WriteLine("Obteniendo configuracion...");

            string path = ConfigurationManager.AppSettings["Path"];
            if (File.Exists(path))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(path);

                #region // Carga información de Manager
                if (xDoc.SelectNodes("//CONFIGURACION_CLIENTE//MANAGER").Count == 1)
                {
                    XmlNode managerNode = xDoc.SelectSingleNode("//CONFIGURACION_CLIENTE//MANAGER");
                    Puerto_manager = int.Parse(managerNode.SelectSingleNode("PUERTO").InnerText);
                    Ip_manager = managerNode.SelectSingleNode("IP").InnerText;
                }
                else
                {
                    Console.WriteLine("Error: configuracion de manager");
                }
                #endregion

            }
            else
            {
                MessageBox.Show("Ruta de configuracion no encontrada..");
                Console.Read();
                Environment.Exit(0);
            }
        }

    }
}
